Title Banner

Previous Book Contents Book Index Next

Inside Macintosh: QuickDraw GX Graphics /
Chapter 4 - Geometric Operations / Using Geometric Operations


Setting a Shape's Bounding Rectangle

The GXGetShapeBounds function, illustrated on page 4-44, allows you to determine the bounding rectangle of a shape. Similarly, the GXSetShapeBounds function allows you to alter the bounding rectangle of a shape, thereby scaling the shape to a new size and moving it to a new location.

As an example, the sample function in Listing 4-8 creates a path with a single circular contour.

Listing 4-8 Creating a circular path

void CreateCircularPath(void)
{
   gxShape      aPathShape;

   static long  circularGeometry[] = {1, /* # of contours */
                                      4, /* # of points */
                                      0xF0000000, /* 1111 ... */
                                      ff(50), ff(50),   /* off */
                                      ff(150), ff(50),  /* off */
                                      ff(150), ff(150), /* off */
                                      ff(50), ff(150)}; /* off */


   aPathShape = GXNewPaths((gxPaths *) circularGeometry);

   GXDrawShape(aPathShape);
   GXDisposeShape(aPathShape);
}
The result of this function is shown in Figure 4-40.

Figure 4-40 A circular path

The bounding rectangle of this shape, which you can determine by calling

GXGetShapeBounds(aPathShape, 0, &theBounds);
is (50.0, 50.0, 150.0, 150.0). You can move and resize this shape by declaring a new bounding rectangle

gxRectangle newBounds = {ff(60), ff(60), ff(110), ff(110)};
and then calling the function

GXSetShapeBounds(aPathShape, &newBounds);
The geometry of the altered shape is centered around the point (85.0, 85.0) and is smaller than the original shape, as showin in Figure 4-41.

Figure 4-41 A circular path after bounding rectangle changed

In this example, the GXSetShapeBounds function actually alters the geometry of the original shape. If you call

GXGetShapeArea(aPathShape, 0, &theArea);
the area returned in the theArea parameter reflects the area of the new, smaller, geometry.

However, if you set the gxMapTransformShape shape attribute of the path shape before setting the shape bounds, QuickDraw GX moves and resizes the shape by changing the information in the shape's transform--not by changing the geometric points of the shape's geometry. In this case, calling the GXGetShapeArea function, which examines only a shape's geometry and ignore its transform mapping, results in the area of the original geometry. The result of declaring a new bounding rectangle and then calling

GXSetShapeAttributes(aPathShape,
                     GXGetShapeAttributes(aPathShape) | 
                      gxMapTransformShape);
GXSetShapeBounds(aPathShape, &newBounds);
GXGetShapeArea(aPathShape, 0, &theArea);
is shown in Figure 4-42.

Figure 4-42 A path shape with a transform mapping

For more information about the GXSetShapeBounds function, see page 4-92. For more information about the GXGetShapeBounds function, see page 4-90.

For more information about the gxMapTransformShape shape attribute, see the chapter "Shape Objects" and the chapter "Transform Objects" of Inside Macintosh: QuickDraw GX Objects.


Previous Book Contents Book Index Next

© Apple Computer, Inc.
7 JUL 1996




Navigation graphic, see text links

Main | Page One | What's New | Apple Computer, Inc. | Find It | Contact Us | Help